package com.mall.product.controller;

import com.mall.api.product.ProductFeignClient;
import com.mall.api.product.dto.ProductDTO;
import com.mall.common.result.Result;
import com.mall.product.service.ProductService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class ProductController implements ProductFeignClient {

    private final ProductService productService;

    @Override
    public Result<ProductDTO> getProductById(Long id) {
        return Result.success(productService.getProductById(id));
    }

    @Override
    public Result<Void> createProduct(ProductDTO productDTO) {
        productService.createProduct(productDTO);
        return Result.success();
    }

    @Override
    public Result<Void> updateProduct(ProductDTO productDTO) {
        productService.updateProduct(productDTO);
        return Result.success();
    }

    @Override
    public Result<Void> deleteProduct(Long id) {
        productService.deleteProduct(id);
        return Result.success();
    }

    @Override
    public Result<Void> updateStock(Long id, Integer stock) {
        productService.updateStock(id, stock);
        return Result.success();
    }

    @Override
    public Result<Integer> getStock(Long id) {
        return Result.success(productService.getStock(id));
    }
} 